<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/19
 * Time: 16:24
 */

namespace App\Http\Controllers;


use App\Game;
use App\Http\Eloquent\GameRepository;
use Illuminate\Http\Request;

class GameController extends  Controller
{
    /**
     * 申请列表
     */
    public function GameList()
    {
        //查询申请列表
        $dataMap = GameRepository::getRowsByMap();
        return response(view('game.index',['datas'=>$dataMap]));
    }
    public function GameEdit(Request $request)
    {
        $gameId = $request->get('gameId');
        if(!$gameId)return response('请求错误',550);

        $r  = GameRepository::first(['id'=>$gameId]);
        if($r)
        {   // 外键约束 对应关系绝对存在 不用if 直接获取
            $gameExt = $r->gameExt;

            return response(view('game.edit',['game'=>$r,'ext'=>$gameExt]));
        }

    }

    /**
     * save game
     *
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function GameSave(Request $request)
    {
        $data = $request->all();

        if($a =GameRepository::updateData($data))
        {
            return $this->GameList();
        }
        return response('保存失败',550);
    }

}